﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Comp476Project
{
    class EffectsHandler
    {
        public List<ParticleSystem> effects;
        public Primitives3D.GeometricPrimitive sphere;
        static Random rand = new Random();
        double timer, dt;

        public EffectsHandler(GraphicsDevice graphicsDevice, ref Matrix projection)
        {
       
            sphere = new Primitives3D.SpherePrimitive(graphicsDevice, 1, 4);
          
            effects = new List<ParticleSystem>();
            //float worldSize = 100, snowWorldSize = 35;
            timer = 0;
            dt = 5;
            // Sample
            //effects.Add(new ParticleSystem(particleModel, ref projection, type, N, duration, gravity, particleSize, sizeOffset, sizeMod, color, alphaChange, speed,
            //                                        speedOffset, rotate, sourcePosition, sourceOffset, direction, directionOffset, wind, spawn));
            // Cloud
            //Color cloudColor = Color.White;
            //cloudColor.A = 200;
            //for (int clouds = 0; clouds != 75; clouds++)
            //{
            //    Vector3 position = new Vector3((float)rand.NextDouble() * worldSize - (worldSize / 2),
            //                                    (float)rand.NextDouble() * 5 + 5,
            //                                    (float)rand.NextDouble() * worldSize - (worldSize / 2));
            //    float duration = 45000 + (float)rand.NextDouble() * 15000;
            //    effects.Add(new ParticleSystem(particleModel, ref projection, 2, 35, duration, false, 1.5f, 1.0f, 0, cloudColor, false, 0.01f,
            //                                        0, false, position, new Vector3(7.50f, 1.50f, 4.50f), new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0), duration + 1000));
            //}
            // Smoke
            Color smokeColor = Color.OrangeRed;
            //Vector3 tipPos = new Vector3(0.25f, 1.5f, 1);
            float smokeDuration = 3000;
            effects.Add(new ParticleSystem(sphere, ref projection, 2, 10, smokeDuration, false, 0.0001f, 0.00005f, 0.00009f, smokeColor, true, 0.0001f,
                                                    0.00009f, false, new Vector3(-0.075f, 0.07f, -0.66f), new Vector3(0.00025f, 0.00010f, 0.00025f), new Vector3(0, 0.0002f, 0), new Vector3(0.00005f, 0, 0.00005f), new Vector3(0, 0, 0), 0));
            // TBA
        }

        public void Update(GameTime gametime)
        {
            timer += gametime.ElapsedGameTime.TotalMilliseconds;
            if (timer > dt)
            {
                foreach (ParticleSystem ps in effects)
                {
                    ps.Update(gametime);
                }
                timer = 0;
            }
        }

        public void Draw(Matrix view)
        {
            foreach (ParticleSystem ps in effects)
            {
                ps.Draw(view);
            }
        }
    }
}
